import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
// import 'package:appsflyer_sdk/appsflyer_sdk.dart';
import 'package:zentoon_flutter/router/app_router.dart';

import 'theme/app_theme.dart'; // 导入 AppsFlyer 插件
// 导入平台特定实现

void main() async {
  // 在应用启动时初始化 AppsFlyer SDK

  WidgetsFlutterBinding.ensureInitialized();

  // final afService = AppsFlyerService();
  // await afService.initSdk();

  // await afService.logEvent("af_app_opened", {});

  // 全局配置
  EasyLoading.instance
    ..displayDuration = const Duration(milliseconds: 2000)
    ..indicatorType = EasyLoadingIndicatorType.fadingCircle
    ..loadingStyle = EasyLoadingStyle.dark
    ..indicatorSize = 45.0
    ..radius = 10.0
    ..progressColor = Colors.yellow
    ..backgroundColor = Colors.green
    ..indicatorColor = Colors.yellow
    ..textColor = Colors.white
    ..maskType = EasyLoadingMaskType.black
    ..userInteractions = true
    ..dismissOnTap = false;

  runApp(
    ProviderScope(
      // overrides: [
      //   appsFlyerProvider.overrideWithValue(afService),
      // ],
      child: const ZenToonApp(),
    ),
  );
}

class ZenToonApp extends ConsumerWidget {
  const ZenToonApp({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final router = ref.watch(appRouterProvider);

    return MaterialApp.router(
      title: 'ZenToon',
      theme: AppTheme.lightTheme,
      darkTheme: AppTheme.darkTheme,
      themeMode: ThemeMode.light,
      routerConfig: ref.watch(appRouterProvider),
      debugShowCheckedModeBanner: false,
      builder: (context, child) {
        // 初始化EasyLoading
        child = EasyLoading.init()(context, child);

        // 设置状态栏颜色为白色，状态栏文字为深色（黑色）
        return AnnotatedRegion<SystemUiOverlayStyle>(
          value: const SystemUiOverlayStyle(
            // 状态栏颜色（Android）
            statusBarColor: Colors.white,
            // 状态栏图标亮度（Android）：dark表示黑色图标
            statusBarIconBrightness: Brightness.dark,
            // 状态栏文字亮度（iOS）：dark表示黑色文字
            statusBarBrightness: Brightness.light,
          ),
          child: child,
        );
      },
    );
  }
}

/**
 * 
 * class PremiumScreen extends ConsumerWidget {
  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final af = ref.read(appsFlyerProvider);

    return ElevatedButton(
      onPressed: () {
        af.logEvent("firstRecharge", {"value": 100});
      },
      child: const Text("上报充值事件"),
    );
  }
}
 */
